﻿namespace Anmlz.Data.UnitOfWork
{
    using System;

    using Anmlz.Data.Contracts;
    using Anmlz.Model.Entities;
    using Anmlz.Services.Contracts;

    public partial class UnitOfWork : IUnitOfWork, IDisposable
    {
        private readonly ILanguageService languageService;

        public AnmlzDbContext DbContext { get; private set; }

        public UnitOfWork(AnmlzDbContext dbContext,
            ILanguageService languageService,
            IRepository<User> users,
            IRepository<UserType> userTypes,
            IRepository<BreedGroup> breedGroups,
            IRepository<Breed> breeds,
            IRepository<BreedToCreatureTemperament> breedToCreatureTemperaments,
            IRepository<BreedToCreatureColor> breedToCreatureColors,
            IRepository<BreedToCreatureCharacteristic> breedToCreatureCharacteristics,
            IRepository<City> cities,
            IRepository<Country> countries,
            IRepository<Creature> creatures,
            IRepository<CreatureColor> creatureColors,
            IRepository<CreatureSizeType> creatureSizeTypes,
            IRepository<CreatureTemperament> creatureTemperaments,
            IRepository<CreatureType> creatureTypes,
            IRepository<Currency> currencies,
            IRepository<UserRole> userRoles,
            IRepository<UserWebsiteUrl> userWebsiteUrls,
            IRepository<Image> images,
            IRepository<ImageToUser> imageToUsers,
            IRepository<ImageToCreature> imageToCreatures,
            IRepository<SellingAd> sellingAds,
            IRepository<ImageToSellingAd> imageToSellingAds,
            IRepository<CreatureCharacteristic> creatureCharacteristics
            )
        {
            this.languageService = languageService;

            this.DbContext = dbContext;
            this.Users = users;
            this.UserTypes = userTypes;
            this.BreedGroups = breedGroups;
            this.Breeds = breeds;
            this.BreedToCreatureTemperaments = breedToCreatureTemperaments;
            this.BreedToCreatureColors = breedToCreatureColors;
            BreedToCreatureCharacteristics = breedToCreatureCharacteristics;
            this.Cities = cities;
            this.Countries = countries;
            this.Creatures = creatures;
            this.CreatureColors = creatureColors;
            this.CreatureSizeTypes = creatureSizeTypes;
            this.CreatureTemperaments = creatureTemperaments;
            this.CreatureTypes = creatureTypes;
            this.Currencies = currencies;
            this.UserRoles = userRoles;
            this.UserWebsiteUrls = userWebsiteUrls;
            this.Images = images;
            this.ImageToUsers = imageToUsers;
            this.ImageToCreatures = imageToCreatures;
            this.SellingAds = sellingAds;
            this.ImageToSellingAds = imageToSellingAds;

            this.CreatureCharacteristics = creatureCharacteristics;
        }

        public IRepository<UserType> UserTypes { get; private set; }
        public IRepository<BreedGroup> BreedGroups { get; private set; }
        public IRepository<Breed> Breeds { get; private set; }
        public IRepository<BreedToCreatureTemperament> BreedToCreatureTemperaments { get; private set; }
        public IRepository<BreedToCreatureColor> BreedToCreatureColors { get; private set; }
        public IRepository<BreedToCreatureCharacteristic> BreedToCreatureCharacteristics { get; private set; }
        public IRepository<City> Cities { get; private set; }
        public IRepository<Country> Countries { get; private set; }
        public IRepository<Creature> Creatures { get; private set; }
        public IRepository<CreatureColor> CreatureColors { get; private set; }
        public IRepository<CreatureSizeType> CreatureSizeTypes { get; private set; }
        public IRepository<CreatureType> CreatureTypes { get; private set; }
        public IRepository<CreatureTemperament> CreatureTemperaments { get; private set; }
        public IRepository<UserRole> UserRoles { get; private set; }
        public IRepository<User> Users { get; private set; }
        public IRepository<UserWebsiteUrl> UserWebsiteUrls { get; private set; }
        public IRepository<Image> Images { get; private set; }
        public IRepository<Currency> Currencies { get; private set; }
        public IRepository<ImageToUser> ImageToUsers { get; private set; }
        public IRepository<ImageToCreature> ImageToCreatures { get; private set; }
        public IRepository<SellingAd> SellingAds { get; private set; }
        public IRepository<ImageToSellingAd> ImageToSellingAds { get; private set; }
        public IRepository<CreatureCharacteristic> CreatureCharacteristics { get; private set; }


        public bool Save()
        {
            return this.DbContext.SaveChanges() > 0;
        }

        public void Dispose()
        {
            if (this.DbContext == null)
            {
                return;
            }
            this.DbContext.Dispose();
            this.DbContext = null;
        }
    }
}